package com.tbit.uqbike.service.business.impl;

import cn.hutool.core.collection.CollUtil;
import com.tbit.uqbike.object.pojo.UpKeepTypeLog;
import com.tbit.uqbike.service.business.UpKeepTypeLogService;
import com.tbit.uqbike.webmanager.dao.log.UpKeepTypeLogDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author yao
 * @since 2025/2/18 14:21
 */
@Service
public class UpKeepTypeLogServiceImpl implements UpKeepTypeLogService {

    @Resource
    private UpKeepTypeLogDao upKeepTypeLogDao;

    @Override
    public void saveBatch(List<UpKeepTypeLog> upKeepTypeLogs) {
        upKeepTypeLogDao.insertBatch(upKeepTypeLogs);
    }

    @Override
    public List<UpKeepTypeLog> getByUpKeepLogId(Integer upKeepLogId) {
        return upKeepTypeLogDao.selectByUpKeepLogId(upKeepLogId);
    }

    @Override
    public Map<Integer, List<UpKeepTypeLog>> getByUpKeepLogIds(List<Integer> upKeepLogIds) {
        if (CollUtil.isEmpty(upKeepLogIds)) {
            return Collections.emptyMap();
        }

        List<UpKeepTypeLog> upKeepTypeLogs = upKeepTypeLogDao.selectByUpKeepLogIds(upKeepLogIds);

        return upKeepTypeLogs.stream().collect(Collectors.groupingBy(UpKeepTypeLog::getUpKeepLogId));
    }

}
